package thinking.in.spring.boot.samples.ienable.selctor;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;


public class ServerImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {

        // 读取Enable中所有的属性方法，key伟属性方法名称，value伟方法返回的对象
        Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableServer.class.getName());
        Server.Type type = (Server.Type)attributes.get("type");
        //导入类名数组
        String[] importClassNames = new String[0];
        switch (type){
            case FTP:
                importClassNames = new String[]{HttpServer.class.getName()};
                break;
            case HTTP:
                importClassNames = new String[]{FtpServer.class.getName()};
                break;
        }
        return importClassNames;
    }
}
